#ifndef __MONITOR_H__
#define __MONITOR_H__

#include "lock/semaphore.h"

typedef struct condvar_t condvar_t;
typedef struct monitor_t monitor_t;

// condition variable
struct condvar_t {
    semaphore_t sem;
    int count;
    monitor_t* owner;
};

struct monitor_t {
    semaphore_t mutex;
    semaphore_t next;
    int nextCount;
    condvar_t* cv;
};

void monitor_init(monitor_t* m, size_t cvNum);  //初始化管程
void cond_signal(condvar_t* cvp);               //发出条件信号
void cond_wait(condvar_t* cvp);                 //等待条件信号

#endif